﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Server.communication;
using System.Runtime.Serialization;
using MySql.Data.MySqlClient;
using System.Windows.Forms;

namespace Server.Processes
{
    [DataContract]
    public class LoginRequest : AbstractRequest
    {
        [DataMember]
        private string _userID;
        [DataMember]
        private string _password;

        public LoginRequest(string user, string pass)
        {
            _userID = user;
            _password = pass;
        }

        public override AbstractResponse handleRequest()
        {
            MySqlConnection sc = new MySqlConnection(" server=localhost;user id=root;password=nir7424394;database=katom;persistsecurityinfo=True ");
            MySqlCommand cmd;

            MySqlCommandBuilder commandBuilder = new MySqlCommandBuilder();
            sc.Open();
            cmd = new MySqlCommand("SELECT * FROM user where userID='" + _userID + "' and password='" + _password + "')", sc);
            cmd.ExecuteNonQuery();
            
            if(cmd!=null)
               
            AbstractResponse response = new LoginResponse(LoginResponse.SUCCESS);
           // else
              //  AbstractResponse response = new LoginResponse(LoginResponse.FAIL);
            sc.Close();

            return response;
        }
    }
}
